package tech.threekilogram.notificationtest;

import android.app.Notification;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat.Builder;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
import android.util.Log;

/**
 * @author liujin
 */
public class InputReceiver extends BroadcastReceiver {

      private static final String TAG = InputReceiver.class.getSimpleName();

      @Override
      public void onReceive ( Context context, Intent intent ) {

            Bundle results = RemoteInput.getResultsFromIntent( intent );
            if( results != null ) {
                  CharSequence key_input = results.getCharSequence( "key_input" );
                  Log.e(
                      TAG,
                      "onReceive : " + key_input + " " + Thread.currentThread() + " " + System
                          .currentTimeMillis()
                  );

                  Notification notification = new Builder( context, "MainChannel" )
                      .setSmallIcon( R.drawable.egg_select )
                      .setContentTitle( "new Notification" )
                      .setContentText( "this is a inputReceive notification " )
                      .build();

                  NotificationManagerCompat notificationManager = NotificationManagerCompat
                      .from( context );
                  assert notificationManager != null;
                  notificationManager.notify( 14, notification );
            }
      }
}
